package model_response

import "go-admin/internal/model"

type ListRoleResponse struct {
	CommonId
	IsBanned string `json:"isBanned"` // 是否禁用
	RoleName string `json:"roleName"` // 角色名称
	RoleKey  string `json:"roleKey"`  // 角色key
	CommonCreatedOn
}

type RoleDetailResponse struct {
	CommonId
	RoleName string   `json:"roleName"` // 角色名称
	RoleKey  string   `json:"roleKey"`  // 角色key
	IsBanned string   `json:"isBanned"` // 是否禁用
	Remark   string   `json:"remark"`   // 备注
	MenuIds  []string `json:"menuds"`   // 菜单id集合
}

func ModelToListRoleRes(models []*model.Role) []*ListRoleResponse {
	var list []*ListRoleResponse
	for _, m := range models {
		l := ListRoleResponse{
			CommonId:        CommonId{m.Id},
			RoleName:        m.RoleName,
			RoleKey:         m.RoleKey,
			IsBanned:        m.IsBanned,
			CommonCreatedOn: CommonCreatedOn{CreatedOn: m.CreatedOn},
		}
		list = append(list, &l)
	}
	return list
}

// 模型转详情结构体
func ModelToDetailRoleRes(model *model.Role, menuIds []string) *RoleDetailResponse {
	role := &RoleDetailResponse{
		CommonId: CommonId{Id: model.Id},
		RoleKey:  model.RoleKey,
		RoleName: model.RoleName,
		IsBanned: model.IsBanned,
		Remark:   model.Remark,
		MenuIds:  menuIds,
	}
	return role
}
